package com.hls.mybatis.core;

import java.lang.reflect.Proxy;

import org.springframework.beans.factory.FactoryBean;

public class MyFactoryBean<T> implements FactoryBean<T>{
    
    private Class<T> daoInterface;

    private MyHandler proxy;
    
    public void setDaoInterface(Class<T> daoInterface) {
        this.daoInterface = daoInterface;
    }

    public void setProxy(MyHandler proxy) {
        this.proxy = proxy;
    }

    @Override
    public T getObject() throws Exception {
        // TODO Auto-generated method stub
        return newInstance();
    }

    @Override
    public Class<?> getObjectType() {
        // TODO Auto-generated method stub
        return daoInterface;
    }

    @Override
    public boolean isSingleton() {
        // TODO Auto-generated method stub
        return true;
    }
    @SuppressWarnings("unchecked")
    private T newInstance() {
        return (T) Proxy.newProxyInstance(daoInterface.getClassLoader(), new Class[] { daoInterface }, proxy);
    }
}
